﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SharpMUSH
{
    static public class Convert
    {
         
        public static bool StringToBool(String value)
        {
            switch (value.ToLower())
            {
                case "yes":
                    return true;
                case "no":
                    return false;
                case "true":
                    return true;
                case "false":
                    return true;
                default:
                    return false;
            }
        }

        public static bool IntToBool(int value)
        {
            if(value >= 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static int StringToInt(string value)
        {
            int result;
            try
            {
                result = Int32.Parse(value);
            }
            catch
            {
                result = 0;
            }

            return result;
        }

        /// <summary>
        /// Convert directory sepperators to windows friendly if needed.
        /// </summary>
        /// <param name="path">Path to convert</param>
        /// <returns>String</returns>
        public static string SafePath(string path)
        {
            // We are assuming that no files have a '\' character in their name
            // which *nix systems will allow.
            if(Path.DirectorySeparatorChar == '\\')
            path = path.Replace("/", "{0}");
            string result = String.Format(path,Path.DirectorySeparatorChar);

            return result;
        }
           
    }
}
